﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using LanguagePolish.Base;
using LanguagePolish.Views;

namespace LanguagePolish.ViewModels
{
    public class LoginControlViewModel : BaseViewModel
    {
        public string UserName
        {
            get { return LinksProvider.Model.CurrentUser.UserLogin; }
        }

        public ICommand LogoutCommand { get; private set; }

        public LoginControlViewModel()
        {
            LogoutCommand = new RelayCommand(ExecuteLogout);
        }

        private void ExecuteLogout()
        {
            if (Microsoft.Win32.Registry.CurrentUser.OpenSubKey("TeacherPassword") != null)
                Microsoft.Win32.Registry.CurrentUser.DeleteSubKey("TeacherPassword");
            LoginView lw = new LoginView();
            bool? res = lw.ShowDialog();
            if (res != true)
                Application.Current.Shutdown();
            OnPropertyChanged("UserName");
        }
    }
}
